/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InternalFrame_ubahStatusAdmin.java
 *
 * Created on Nov 24, 2011, 11:15:57 PM
 */
package Boundaries;

import Entities.Kendaraan;
import Entities.Servis;
import TableModel.Kendaraan_List;
import TableModel.Kendaraan_List_TableModel;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Tea-Nose
 */
public class InternalFrame_ubahStatusAdmin extends javax.swing.JInternalFrame {

    /** Creates new form InternalFrame_ubahStatusAdmin */
    String params;

    public InternalFrame_ubahStatusAdmin() {
        try {
            initComponents();
            List<Kendaraan> kendaraans = Kendaraan_List.getKendaraanList().getAllKendaraanServis();
            Kendaraan_List_TableModel kendaraan_TableModel = new Kendaraan_List_TableModel(kendaraans);
            jTable1.setModel(kendaraan_TableModel);
        } catch (SQLException ex) {
            Logger.getLogger(InternalFrame_ubahStatusAdmin.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        label_MerkKendaraanLabel = new javax.swing.JLabel();
        label_NoPolisiKendaraan = new javax.swing.JLabel();
        label_StatusTerakhir = new javax.swing.JLabel();
        tf_statusTerakhir = new javax.swing.JTextField();
        tf_noPolisiKendaraan = new javax.swing.JTextField();
        tf_merkKendaraan = new javax.swing.JTextField();
        label_StatusBaru1 = new javax.swing.JLabel();
        cmbBox_statusBaru = new javax.swing.JComboBox();
        jSeparator2 = new javax.swing.JSeparator();
        button_OK = new javax.swing.JButton();
        button_cancel = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        label_StatusTerakhir1 = new javax.swing.JLabel();
        tf_biayaServis = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();

        setPreferredSize(new java.awt.Dimension(1010, 480));
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setBackground(new java.awt.Color(204, 204, 255));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        label_MerkKendaraanLabel.setText("Merk Kendaraan");
        jPanel1.add(label_MerkKendaraanLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 60, -1, -1));

        label_NoPolisiKendaraan.setText("No Polisi Kendaraan");
        jPanel1.add(label_NoPolisiKendaraan, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 30, -1, -1));

        label_StatusTerakhir.setText("Status Terakhir");
        jPanel1.add(label_StatusTerakhir, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 90, -1, -1));

        tf_statusTerakhir.setEditable(false);
        tf_statusTerakhir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_statusTerakhirActionPerformed(evt);
            }
        });
        jPanel1.add(tf_statusTerakhir, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 90, 90, -1));

        tf_noPolisiKendaraan.setEditable(false);
        tf_noPolisiKendaraan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_noPolisiKendaraanActionPerformed(evt);
            }
        });
        jPanel1.add(tf_noPolisiKendaraan, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 30, 90, -1));

        tf_merkKendaraan.setEditable(false);
        tf_merkKendaraan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_merkKendaraanActionPerformed(evt);
            }
        });
        jPanel1.add(tf_merkKendaraan, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 60, 90, -1));

        label_StatusBaru1.setText("Status Baru");
        jPanel1.add(label_StatusBaru1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 160, -1, -1));

        cmbBox_statusBaru.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "SIAP SEWA", "RUSAK" }));
        cmbBox_statusBaru.setEnabled(false);
        jPanel1.add(cmbBox_statusBaru, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 160, 90, -1));
        jPanel1.add(jSeparator2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 150, 280, -1));

        button_OK.setText("OK");
        button_OK.setEnabled(false);
        button_OK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button_OKActionPerformed(evt);
            }
        });
        jPanel1.add(button_OK, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 230, -1, -1));

        button_cancel.setText("Cancel");
        button_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button_cancelActionPerformed(evt);
            }
        });
        jPanel1.add(button_cancel, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 230, -1, -1));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jPanel1.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 10, 650, 250));

        label_StatusTerakhir1.setText("Biaya Servis");
        jPanel1.add(label_StatusTerakhir1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 190, -1, -1));

        tf_biayaServis.setEditable(false);
        tf_biayaServis.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_biayaServisActionPerformed(evt);
            }
        });
        jPanel1.add(tf_biayaServis, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 190, 90, -1));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 99, 994, 370));

        jLabel1.setBackground(new java.awt.Color(255, 255, 255));
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Boundaries/kembaliServis.jpg"))); // NOI18N
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(950, 0, 50, 100));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tf_statusTerakhirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_statusTerakhirActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_tf_statusTerakhirActionPerformed

    private void tf_noPolisiKendaraanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_noPolisiKendaraanActionPerformed
        try {
            // TODO add your handling code here:
            Kendaraan kendaraan = new Kendaraan();
            kendaraan.setNo_polisi(tf_noPolisiKendaraan.getText());

            params = kendaraan.cariKendaraanKembaliServis(kendaraan);
            if (!params.matches("")) {
                tf_merkKendaraan.setText(kendaraan.getMerk_kendaraan());
                tf_statusTerakhir.setText(kendaraan.getStatus_kendaraan());
                cmbBox_statusBaru.setEnabled(true);
                tf_biayaServis.setEditable(true);
            } else {
                tf_noPolisiKendaraan.setText(null);
                tf_merkKendaraan.setText(null);
                tf_statusTerakhir.setText(null);
                cmbBox_statusBaru.setEnabled(false);
                tf_biayaServis.setEditable(false);
            }

        } catch (Exception ex) {
            Logger.getLogger(InternalFrame_ubahStatusAdmin.class.getName()).log(Level.SEVERE, null, ex);
        }

}//GEN-LAST:event_tf_noPolisiKendaraanActionPerformed

    private void tf_merkKendaraanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_merkKendaraanActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_tf_merkKendaraanActionPerformed

    private void tf_biayaServisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_biayaServisActionPerformed
        // TODO add your handling code here:
        button_OK.setEnabled(true);
    }//GEN-LAST:event_tf_biayaServisActionPerformed

    private void button_OKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button_OKActionPerformed
        try {
            // TODO add your handling code here:
            Servis servis = new Servis();
            servis.dataServisKembali(Double.parseDouble(tf_biayaServis.getText()), params);
            Kendaraan kendaraan = new Kendaraan();
            kendaraan.setStatus_kendaraan(cmbBox_statusBaru.getSelectedItem().toString());
            try {
                kendaraan.setNo_polisi(tf_noPolisiKendaraan.getText().toUpperCase());
            } catch (Exception ex) {
                Logger.getLogger(InternalFrame_ubahStatusAdmin.class.getName()).log(Level.SEVERE, null, ex);
            }
            kendaraan.changeStatusKendaraan();

            List<Kendaraan> kendaraans = Kendaraan_List.getKendaraanList().getAllKendaraanServis();
            Kendaraan_List_TableModel kendaraan_TableModel = new Kendaraan_List_TableModel(kendaraans);
            jTable1.setModel(kendaraan_TableModel);

            button_cancel.doClick();
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Terjadi error");
        } catch (NullPointerException ex) {
            JOptionPane.showMessageDialog(null, "Terjadi error");
        } catch (NumberFormatException ex) {
            JOptionPane.showMessageDialog(null, "Terjadi error");
        }
    }//GEN-LAST:event_button_OKActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        // TODO add your handling code here:
        //InternalFrame_Persewaan formReg = (InternalFrame_Persewaan) internalFrame;
        int row = jTable1.getSelectedRow();

        tf_noPolisiKendaraan.setText(jTable1.getValueAt(row, 0).toString());
        tf_merkKendaraan.setText(jTable1.getValueAt(row, 1).toString());
        tf_statusTerakhir.setText(jTable1.getValueAt(row, 5).toString());

        cmbBox_statusBaru.setEnabled(true);
        tf_biayaServis.setEditable(true);
        button_OK.setEnabled(true);
    }//GEN-LAST:event_jTable1MouseClicked

    private void button_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button_cancelActionPerformed
        // TODO add your handling code here:
        tf_noPolisiKendaraan.setText("");
        tf_merkKendaraan.setText("");
        tf_statusTerakhir.setText("");
        cmbBox_statusBaru.setEnabled(false);
        tf_biayaServis.setEditable(false);
        button_OK.setEnabled(false);

    }//GEN-LAST:event_button_cancelActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton button_OK;
    private javax.swing.JButton button_cancel;
    public javax.swing.JComboBox cmbBox_statusBaru;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator2;
    public javax.swing.JTable jTable1;
    private javax.swing.JLabel label_MerkKendaraanLabel;
    private javax.swing.JLabel label_NoPolisiKendaraan;
    private javax.swing.JLabel label_StatusBaru1;
    private javax.swing.JLabel label_StatusTerakhir;
    private javax.swing.JLabel label_StatusTerakhir1;
    public javax.swing.JTextField tf_biayaServis;
    public javax.swing.JTextField tf_merkKendaraan;
    public javax.swing.JTextField tf_noPolisiKendaraan;
    public javax.swing.JTextField tf_statusTerakhir;
    // End of variables declaration//GEN-END:variables
}
